#include <iostream>
#include <map>
#include <vector>
#include <fstream>
using namespace std;

void MST(const vector< map<int, double> >& g, vector< int >& pred, int from, int to)
{
    int n = g.size();
    vector<bool> was;
    was.assign(n, false);
    was[from] = true;
    was[to] = true;
    pred.clear();
    pred.assign(n, -1);
    pred[to] = from;
    pred[from] = from;
    multimap<double, int> pri_queue;
    for (map<int, double>::const_iterator iter = g[from].begin(); iter != g[from].end(); ++iter)
    {
        if (iter->first != to)
        {
            pri_queue.insert(make_pair(iter->second, iter->first));
        }
    }
    for (map<int, double>::const_iterator iter = g[to].begin(); iter != g[to].end(); ++iter)
    {
        if (iter->first != from)
        {
            pri_queue.insert(make_pair(iter->second, iter->first));
        }
    }
    while (!pri_queue.empty())
    {
        int curr = pri_queue.begin()->second;
        double weight = pri_queue.begin()->first;
        pri_queue.erase(pri_queue.begin());
        if (was[curr])continue;
        was[curr] = true;
        int from_curr;
        for (map<int, double>::const_iterator iter = g[curr].begin(); iter != g[curr].end(); ++iter)
        {
            if (was[iter->first] && iter->second == weight)
            {
                pred[curr] = iter->first;
            }
            if (!was[iter->first])
            {
                pri_queue.insert(make_pair(iter->second, iter->first));
            }
        }
    }
    for (int i = 0; i<n; ++i)
    {
        if (pred[i] == -1)
        {
            cout<<"No";
            return;
        }
    }
    cout<<"Yes\n";
    for (int i = 0; i<n; ++i)
    {
        if (pred[i] != i)
        {
            cout<<i<<' '<<pred[i]<<' '<<g[i].find(pred[i])->second<<endl;
        }
    }
}


int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    vector< map<int, double> > g;
    int n;
    cin>>n;
    g.resize(n);
    int from,to;
    cin>>from>>to;
    int from_temp,to_temp;
    double weight_temp;
    while (cin>>from_temp>>to_temp>>weight_temp)
    {
        g[from_temp][to_temp] = weight_temp;
        g[to_temp][from_temp] = weight_temp;
    }
    if (g[from].find(to) == g[from].end())
    {
        cout<<"No";
        return 0;
    }
    else
    {
        vector<int> pred;
        MST(g, pred, from, to);
    }
    return 0;
}
